<?php
/**
 * Event.php
 *
 * @author Henry<8323216@qq.com>
 * @link http://www.cnblogs.com/lovelife520/
 * @Date 16/2/18 下午3:55
 * @copyright Copyright© 2016-2016 飞煌科技 All Rights Reserved.
 *
 * Code is poetry, thus is life.
 */

namespace App\Services\Wechat;
class Event
{

    /**
     * Event constructor.
     * @param $event
     */
    public function __construct(Member $member)
    {
        $this->member = $member;
    }

    public function handleEvent($message)
    {
        $event = strtolower($message->Event);
        switch($event)
        {
            case 'subscribe':  //关注
                return $this->subscribe($message);
                break;
            case 'unsubscribe':  //取消关注
                return $this->unsubscribe($message);
                break;
            case 'scan':
                return $this->scan($message);
                break;
            case 'location':
                return $this->location();
                break;
            case 'click':
                return $this->click($message);
                break;
            case 'view':
                return $this->view();
                break;

        }
    }

    /**
     *关注
     */
    public function subscribe($message)
    {
        $msg = $this->member->subscribe($message);
        return $msg;
    }

    /**
     *取消关注
     */
    public function unsubscribe($message)
    {
        $this->member->unsubscribe($message);
        return true;
    }

    public function scan($message)
    {
        //return $this->subscribe($message);
    }

    public function location()
    {
        return '您好！overtrue3。';
    }

    public function click($message)
    {
        return $message['EventKey'];
    }

    public function view()
    {
        return '您好！overtrue5。';
    }
}